package com.project.sianet;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.project.sianet.util.SessionManager;

public class DispatcherActivity extends Activity {

	// Session Manager Class
    SessionManager session;
	
	@Override
    protected void onCreate(Bundle savedInstanceState) { 
		super.onCreate(savedInstanceState);
		
		// Session Manager
        session = new SessionManager(getApplicationContext());
        Intent notifIntent = getIntent();
		
		Class<?> activityClass;
        
        try {
        	
        	if (session.isLoggedIn()) {

        		activityClass = Class.forName(session.getLastActivity());
        		
        	} else
        		activityClass = LoginActivity.class;
        	
        } catch (ClassNotFoundException ex) {
        	activityClass = LoginActivity.class;
        }
        
        Intent i = new Intent(this, activityClass);
        //i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        
        try {

        	String action = notifIntent.getAction();
        	
        	if (action.equalsIgnoreCase("M") || action.equalsIgnoreCase("N"))
        		i.setAction(notifIntent.getAction());
        	
        } catch(Exception ex) { }
        
        startActivity(i);
        finish();
		
	}
	
}
